<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!-- required -->
<link href="${ctx}/frontStatic/jurisdiction.css" type="text/css"
	rel="stylesheet" />

<script type="text/javascript">
	$(function() {
		//模块全选/反选
		$("#chkAll").click(function() {
			$('input[name="menuId"]').prop("checked", this.checked);
			$('input[name="funcId"]').prop("checked", this.checked);
		});

		//选中或取消菜单时，同步其权限的选择效果
		$("input[name='menuId']").click(function() {
			$("input[title='" + this.id + "']").prop("checked", this.checked);
		});

		//如果选中一个权限，则同时选择他所属的菜单
		$("input[name='funcId']").click(function() {
			if (this.checked) {
				$("#" + this.title).prop("checked", true);
			}
		});

		$("#role_setFunc_ok").click(function() {
			//拼接选中的菜单ID集合
			var menuCheckeds = $("input[name='menuId']");
			var menuIds = "";
			for ( var i = 0; i < menuCheckeds.length; i++) {
				var mc = menuCheckeds[i];
				if (mc.checked) {
					menuIds += mc.id + ",";
				}
			}
			menuIds = menuIds.substr(0, menuIds.length - 1);

			//拼接选择的权限ID集合
			var funcCheckeds = $("input[name='funcId']");
			var funcIds = "";
			for ( var i = 0; i < funcCheckeds.length; i++) {
				var fc = funcCheckeds[i];
				if (fc.checked) {
					funcIds += fc.id + ",";
				}
			}
			funcIds = funcIds.substr(0, funcIds.length - 1);

			//保存当前角色所属的菜单和权限
			$.post("role/setFunc", {
				roleId : $("#role_setFunc_roleId").val(),
				menuIds : menuIds,
				funcIds : funcIds
			}, function(data) {
				$("#role_edit_dialog").dialog("close");
			});
		});

		$("#role_setFunc_cancel").click(function() {
			$("#role_edit_dialog").dialog("close");
		});
	});

</script>

<div style="position: relative; left: 0px; top: 10px; margin:auto;">
	<input type="hidden" id="role_setFunc_roleId" name="roleId" value="${roleId }" />
	<input type="hidden" name="bindable" value="true" />
	<div style="margin: 5px;">
		<div id="role_func_content" class="divtable">
			<!-- 行头 -->
			<div class="divrowheader">
				<div class="divtd1">
					<input type="checkbox" name="chkAll" id="chkAll" /> 模块名称
				</div>
				<div class="divtd2">操 作</div>
			</div>
			<!-- 每一行 -->
			<c:forEach var="menu" items="${menus }">
				<div class="divtr">
					<div class="divtd1">
						<input type="checkbox" name="menuId" id="${menu.id }"
							<c:if test="${menu.selected}"> checked='checked' </c:if>
							value="${menu.id }" /> ${menu.menuname }
					</div>
					<div class="divtd2">
						<c:forEach var="func" items="${menu.fvos }">
							<input type="checkbox" title="${menu.id }" name="funcId"
								<c:if test="${func.selected}"> checked='checked' </c:if>
								value="${func.id }" id="${func.id}" /> ${func.funcName}
	            		   </c:forEach>
					</div>
				</div>
			</c:forEach>
		</div>
	</div>

	<a id="role_setFunc_ok" class="easyui-linkbutton"
		data-options="iconCls:'icon-ok'">确定</a> <a id="role_setFunc_cancel"
		class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a>
</div>